require('../css/index.css');
//导入local
const local = require('../utils/local.js');
//导入sxios
const axios = require('../utils/http.js');



window.addEventListener('load', function () {
    let rank_num = document.querySelector('.rank_num');
    let clockCount = document.querySelector('.clock_tit span');
    let clock_btn = document.querySelector('.clock_btn');

    let sportData = document.querySelector('.sport_data');
    let curriculumDom = document.querySelector('.curriculum');
    let badgeDom = document.querySelector('.badge');

    //点击运动数据跳转
    sportData.addEventListener('click',function(){
        location.href = './echarts.html';
    })
     //点击课程介绍跳转
     curriculumDom.addEventListener('click',function(){
        location.href = './sport.html';
    })
     //点击运动徽章跳转
     badgeDom.addEventListener('click',function(){
        location.href = './badge.html';
    })



    //判断打卡按钮显隐
    function getClockInfo() {
        axios.get('/api/user/clockInInfo').then(res => {

            console.log(res.data.data);
            let num = res.data.data.clockCount;
            clockCount.innerText = num;
            if (res.data.data.isClockIn == true) {
                clock_btn.style.display = 'none';
            }
        })
    }
    getClockInfo()

    //点击打卡
    clock_btn.addEventListener('click', function () {
        axios.post('/api/user/clockIn').then(res => {
            console.log(res);

            if (res.data.errno == 0) {
                utils.toast(0, '打卡成功');
            }
            getClockInfo()

        })
    })


    //排名页面刷新
    axios.get('/api/user/info').then(res => {

        // console.log(res.data.data);
        rank_num.innerText = res.data.data.ranking;

    })


    //swiper
    var mySwiper = new Swiper ('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay:{
            delay:2000
        },
        
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
        },
        
        // 如果需要前进后退按钮
        // navigation: {
        //   nextEl: '.swiper-button-next',
        //   prevEl: '.swiper-button-prev',
        // },
        
        // 如果需要滚动条
        // scrollbar: {
        //   el: '.swiper-scrollbar',
        // },
      })        

      //调用底部
      utils.footer('index');





})

